<?php
/**
 *      [迷你云] (C)2009-2012 南京恒为网络科技.
 *   软件仅供研究与学习使用，如需商用，请访问www.miniyun.cn获得授权
 * 
 */
?>
<?php

class OnlineBase extends MiniyunViewForm {
    public $id;     public $userID;     public $avatar;     public $name;      public $appname;     public $deviceType;      public $deviceName;     public $did;
    public $appid;
    public $lastLoginTime;
    
    public function init() {
    }
    
    
    public function attributeLabels() {
        return array ("name" => "用户名", "appname" => "应用名称", "deviceName" =>"设备名称", "lastLoginTime" => "登陆时间" );
    }
    
    
    public function load($userId) {
        $user = User::model ()->find ( "id=?", array ($userId ) );
        if (! empty ( $user )) {
            $this->id = $userId;
            $this->name = $user ['user_name'];
            $userMeta = new UserMeta ();
            $metas = $userMeta->getUserBaseMate ( $userId );
            if (! empty ( $metas )) {
                foreach ( $metas as $index => $item ) {
                                        if ($item->meta_key == "avatar") {
                        $this->avatar = $item->meta_value;
                    }
                }
            }
            $handleUserDevice      = new UserDevice();
                        $apps = ServerRegistry::getApps();
            $device   = $handleUserDevice->findByPk($this->did);
            $online->appname = $apps["{$this->appID}"];            $online->deviceType = $device["user_device_type"];
            $online->deviceName = $device["user_device_name"];
        }
    }
    
    public function  getItemOperates() {
        return;
    }
    
    
    public function nameDetail() {
        $name = $this->name;
        if (strlen ( $name ) > 13) {
            $name = substr ( $name, 0, 10 ) . "...";
        }
        return "<img src='" . Yii::app ()->request->baseUrl . $this->avatar . "' style='width:32px'>" . CHtml::link ( $this->name, Yii::app ()->createUrl ( "adminUserPanel/show", array ('id' => $this->userID ) ) );
    }
    
    
    public function appnameDetail() {
        $appname = $this->appname;
        $appid   = $this->appid;
        $appIcons = ServerRegistry::getAppIcons();
        return "<img src='" . Yii::app ()->request->baseUrl . $appIcons[$appid] . "' style='width:32px'>" . $appname;
    }
}
?>